//
//  MovieViewController.m
//  newDouban
//
//  Created by dllo on 15/10/17.
//  Copyright © 2015年 蓝鸥科技. All rights reserved.
//

#import "MovieViewController.h"
#import "MovieDetailViewController.h"
#import "MovieListViewController.h"
@interface MovieViewController ()

@property (nonatomic, retain) MovieDetailViewController *detailVC;
@property (nonatomic, retain) MovieListViewController *listVC;
@property (nonatomic, assign) NSInteger a;
@property (nonatomic, retain) UIImage *listImage;
@property (nonatomic, retain) UIImage *collectionImage;

@end

@implementation MovieViewController


- (void)dealloc
{
    [_listImage release];
    [_collectionImage release];
    [_detailVC release];
    [_listVC release];
    [super dealloc];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    self.navigationItem.title = @"电影";
    
    
    self.detailVC = [[MovieDetailViewController alloc] init];
    [self addChildViewController:self.detailVC];
    [self.view addSubview:self.detailVC.view];
    [_detailVC release];
    
    
    
    self.listVC = [[MovieListViewController alloc] init];
    [self addChildViewController:self.listVC];
    [self.view addSubview:self.listVC.view];
    [_listVC release];

    
    [self.view bringSubviewToFront:self.listVC.view];
    //[self.view bringSubviewToFront:self.detailVC.view];
    
    
    self.listImage = [UIImage imageNamed:@"btn_nav_list@2x.png"];
    self.listImage = [self.listImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    
    self.collectionImage = [UIImage imageNamed:@"btn_nav_collection@2x.png"];
    self.collectionImage = [self.collectionImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    
     self.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc] initWithImage:self.collectionImage style:UIBarButtonItemStylePlain target:self action:@selector( detailAction:)] autorelease];
    
    //注意给一个变量赋值为1 真
    self.a = 1;
}


- (void)detailAction:(UIBarButtonItem *)sender
{
    if (self.a) {
        [self.view bringSubviewToFront:self.detailVC.view];
        self.navigationItem.rightBarButtonItem.image = self.listImage;
        //self.a = 0;
        self.a = !self.a;
    } else {
        [self.view bringSubviewToFront:self.listVC.view];
        self.navigationItem.rightBarButtonItem.image = self.collectionImage;
        //self.a = 1;
        self.a = !self.a;
    }

}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
